﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 税控接口
{
    class ServerConfig
    {
        public static string ServerAddress;
        public static string UserName;
        public static string PassWord;
        public static string Token;
        public static DateTime Version = new DateTime(2017, 12, 1);

        #region 获取登录的token--覃豪@20170225
        /// <summary>
        /// 获取登录的token
        /// </summary>
        /// <param name="cAddress">服务器地址</param>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        public static void Login()
        {
            #region 获取登录的token
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("UserName", UserName);// "printControl"
            dic.Add("Password", PassWord);// "cSysAABBCCaaa"  
            dic.Add("SystemCode", 1171);
            var url = ServerAddress + "/api/oms/SysCommon/Login";
            string s = Common.handleHttp.Post(dic, url);
            var d1 = Common.handleJSON.Deserialize(s);
            var suc = d1["result"].ObjToInt();
            if (suc == -1)
            {
                var err = d1["resultdetail"].ObjToString();
                throw new Exception("出现错误" + Environment.NewLine + err);
            }
            Token = d1["token"].ObjToString();
            #endregion
        }

        public static void ReLogin()
        {
            if (Token == null || Token.Length == 0)
            {
                var f = new FrmLogin();
                f.ShowDialog();
            }
        }
        #endregion
    }
}
